<template>
  <section ref="wrapper">
    <div>
      <home-header :city="city"></home-header>
      <home-swiper :swiperList="swiperList"></home-swiper>
      <home-icons :iconList="iconList"></home-icons>
      <home-recommend :recommendList="recommendList"></home-recommend>
      <home-weekend :weekendList="weekendList"></home-weekend>
    </div>
  </section>
</template>

<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import axios from 'axios'
import BScroll from 'better-scroll'

export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend
  },
  data () {
    return {
      city: '',
      iconList: [],
      swiperList: [],
      recommendList: [],
      weekendList: []
    }
  },
  methods: {
    getHomeInfo () {
      axios.get('/api/index.json').then(this.getHomeInfoSuc)
    },
    getHomeInfoSuc (res) {
      const resdata = res.data
      if (resdata.ret === true) {
        this.city = resdata.data.city
        this.iconList = resdata.data.iconList
        this.swiperList = resdata.data.swiperList
        this.recommendList = resdata.data.recommendList
        this.weekendList = resdata.data.weekendList
      }
    }
  },
  mounted () {
    this.getHomeInfo()
    this.scroll = new BScroll(this.$refs.wrapper)
  }
}
</script>

<style scoped>
  section {
    overflow: hidden;
  }
</style>
